const hour = date=>{
  const h=date.getHours()
  return h
}
const mins =date =>{
  const m=date.getMinutes()
  return m
}
const dates =date=>{
  const hours = date.getHours().toString().padStart(2,"0")
  const minute = date.getMinutes().toString().padStart(2,"0")
  const second = date.getSeconds().toString().padStart(2,"0")
  return [hours, minute, second].map(formatNumber).join(':')
}
const formatTime = date => {
  const year = date.getFullYear()
  const month = (date.getMonth() + 1).toString().padStart(2,"0")
  const day = date.getDate().toString().padStart(2,"0")
  const hours = date.getHours().toString().padStart(2,"0")
  const minute = date.getMinutes().toString().padStart(2,"0")
  const second = date.getSeconds().toString().padStart(2,"0")
  
  return [year, month, day].map(formatNumber).join('/') + ' ' + [hours, minute, second].map(formatNumber).join(':')
}
let getYmd =date =>{
  let year = date.getFullYear()
  let month = (date.getMonth() + 1).toString().padStart(2,"0")
  let day = date.getDate().toString().padStart(2,"0")
  // if(month<10){
  //   month="0"+month
  // }
  return [year, month, day].map(formatNumber).join('.')
}
const getYN =date=>{
  const year=date.getFullYear()
  let mon=(date.getMonth()+1).toString().padStart(2,"0")
  // if(mon<10){
  //   mon="0"+mon
  // }
  return [year, mon].map(formatNumber).join('-')
}
const getMDC=date=>{
  const M=(date.getMonth()+1).toString().padStart(2,"0")
  const d=date.getDate().toString().padStart(2,"0")
  let week=date.getDay()
  // console.log(week)
  switch(week){
    case 1: week="周一";break;
    case 2: week="周二";break;
    case 3: week="周三";break;
    case 4: week="周四";break;
    case 5: week="周五";break;
    case 6: week="周六";break;
    case 0: week="周日";break;
  }
  return M+"月"+d+"日"+"  " +week
}
const getWeek= date=>{
  let week=date.getDay()
  // console.log(week)
  switch(week){
    case 1: week="周一";break;
    case 2: week="周二";break;
    case 3: week="周三";break;
    case 4: week="周四";break;
    case 5: week="周五";break;
    case 6: week="周六";break;
    case 0: week="周日";break;
  }
  return week
}
const getTime =date=>{
  const hours = date.getHours().toString().padStart(2,"0")
  const minute = date.getMinutes().toString().padStart(2,"0")
  return [hours, minute].map(formatNumber).join(':')
}
const formatNumber = n => {
  n = n.toString().padStart(2,"0")
  // return n[1] ? n : '0' + n
  return n
}

module.exports = {
  formatTime: formatTime,
  formatNumber:formatNumber,
  hour:hour,
  dates :dates,
  mins:mins,
  getYmd:getYmd,
  getTime:getTime,
  getYN:getYN,
  getMDC,
  getWeek
}
